﻿using System;
using System.Collections.Generic;
using System.Web;

using JigsawService.Parsers;
using JigsawService.Utility;
using JigsawService.DataAccess.Usage;

namespace JigsawService.Controllers
{
    public class Events
    {
        APIMessage _apimessage;

        public Events(APIMessage apiMessage)
        {
            _apimessage = apiMessage;
        }


        /// <summary>
        /// The Events controller provides external access to methods used to store specific types of events:
        /// Each method builds an XML fragment from its own method parameters, to be stored by the generic SaveEvent method 
        /// (which is not publicly accessible).
        /// </summary>
        public void Controller()
        {
            _apimessage.StateMessage = "Events Controller: ";

            // method access authorization
            if (_apimessage.ValidateMethodAccess(_apimessage.APIString))
            {
                switch (_apimessage.APIString)
                {
                    case "Events.Clickstream.Base":
                        ClickStream();
                        break;



                }
            }
            else
            {
                throw new Exception("Method Authorization Failed for " + _apimessage.APIString);
            }
        }


        // ********************************************************************
        // ********************************************************************
        // ********************************************************************

        /// <summary>
        /// 
        /// </summary>
        protected void ClickStream()
        {
            _apimessage.StateMessage = "Events ClickStream: ";

            string appname = _apimessage.ValidateMethodParam("AppName");
            string appeventname = _apimessage.ValidateMethodParam("AppEventName");

            if (appname != "" && appeventname != "")
            {
                EventLogDA evtlogda = new EventLogDA(_apimessage);
                evtlogda.ClickStream(appname, appeventname);
            }
            else
            {
                throw new Exception("ClickStream method failed due to missing input parameter(s)");
            }
        }
    }
}